<!doctype html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <meta name="Generator" content="EditPlus®">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
  <title>Document</title>
 </head>
 <body>
    <button id="btn_1">开始计时</button>
	<input type="text" id="text">
	<button id="btn_2">停止计时</button>
 </body>
 <script>
     var $ = function(obj){
	    return document.getElementById(obj);
	 }
	 window.onload = function(){
	    var i= 0;
		var s;
		var text = $("text");
		//开始计时
		$("btn_1").onclick = function(){
		    s = window.setInterval(start,1000);
		}

        $("btn_2").onclick = function(){
		   clearInterval(s);
		}
		function start(){
	        text.value = ++i;
	    }
	 }
	  
 </script>
</html>
